package com.cyber.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cyber.entity.Food;
import com.cyber.service.IFoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Book;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmj
 * @since 2022-02-27
 */
@RestController
@RequestMapping("/food")
public class FoodController {
    @Autowired
    private IFoodService fs;
    @GetMapping("/selectAll")
    public List<Food> selectAll(Integer cid){
        QueryWrapper<Food> wrapper=new QueryWrapper<>();
        if(cid!=null){
            wrapper.eq("cid",cid);
        }
        return fs.list(wrapper);
    }
    @PostMapping("/add")
    public void add(@RequestBody Food food){
        fs.save(food);
    }
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") int id){
        fs.removeById(id);
    }
}

